package net.takela.common.spring.message;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;

/**
 * @author baboy
 * create at 2023/1/22
 */
public class MessageSource extends ResourceBundleMessageSource {
    private static Logger logger = LoggerFactory.getLogger(MessageSource.class);
    private static MessageSource instance;
    /**
     * 
     */
    public MessageSource() {
    }
    /**
     * 
     */
    public static String getMessage(String code, Object... args) {
        try {
            return instance.getMessage(code, args, LocaleContextHolder.getLocale());
        } catch (NoSuchMessageException var3) {
            return code;
        }
    }

    
    /**
     * 
     */
    @PostConstruct
    public void init() {
        logger.info("MessageSource init");
        instance = this;
    }
}